// pages/person/score.js
const order = ['demo1', 'demo2', 'demo3']
var core = require('../../utils/core.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 200,
    index:0,
    visite:[
      {"id":1,'title':'邀请好友','remark':'+2000/人','desc':'每邀请一个好友，获得2000金币','go':'去邀请','url':'/pages/person/visite'},
      {"id":2,'title':'绑定联系方式','remark':'+10000','desc':'绑定联系方式立送10000金币','go':'去绑定','url':''},
      {"id":3,'title':'绑定微信公众号','remark':'+10000','desc':'绑定微信公众号10000金币','go':'去绑定','url':'/pages/index/index'},
      {"id":4,'title':'发布产业项目','remark':'+100000/条','desc':'每发布一条产业项目，审核通过后100000金币','go':'去发布','url':'/pages/release/project'},
      {"id":5,'title':'发布产业报告','remark':'+10000/条','desc':'每发布一条产业报告，审核通过后送10000金币','go':'去发布','url':'/pages/release/report'},
      {"id":6,'title':'发布附近群信息','remark':'+2000/条','desc':'每发布一条附近群，审核通过后送2000金币','go':'去发布','url':'/pages/release/group'},
      {"id":7,'title':'好友消费','remark':'+40%/笔','desc':'好友每次消费完成后可获得40%返利','go':'去邀请','url':'/pages/person/visite'},
    ],
    userlist:[
      {'id':'1','title':'查看产业项目更多信息','credit1':''},
      {'id':'2','title':'下载产业报告','credit1':''},
      {'id':'3','title':'查看群更多信息','credit1':''},
    ],


    list_page:1,
    list:[],
    list_fresh:false,

    fee_page:1,
    fee:[],
    fee_fresh:false,

    credit1:0,
    credit2:0,
  },

  more(){
    console.log(1111)
    //我的需求
    if(this.data.index==1){
       this.getScoreList()
    }
    if(this.data.index==2){
      this.getFeeList()
   }
 },
 onRefresh(){
   console.log(this.data.index)
   //我的需求
   if(this.data.index==1){
     this.setData({
       list_page:1,
       list:[],
       list_fresh:true
     })
      this.getScoreList()
   }
   if(this.data.index==2){
    this.setData({
      fee_page:1,
      fee:[],
      fee_fresh:true
    })
     this.getFeeList()
  }
 },
 

  changeIndicatorDots() {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
 
  changeAutoplay() {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },

  intervalChange(e) {
    this.setData({
      interval: e.detail.value
    })
  },

  durationChange(e) {
    this.setData({
      duration: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
        this.getScoreList()
        this.getFeeList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
     this.GetUserInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


  /**
   * 获得用户信息
   */
  GetUserInfo:function(){
    var self=this
    core.post("GetUserinfo",{},function(res){
      if(res.code==1){
          var visite=self.data.visite;
          if(res.data.mobile){
            visite[1].go='已完成';
          }else{
            visite[1].go='去绑定';
            visite[1].url='/pages/person/person';
          }
          self.setData({visite:visite,credit1:res.data.credit1,credit2:res.data.credit2})      
      }
    })
  },
  //提现页面跳转
  withdraw:function(){
    wx.navigateTo({
      url:"/pages/person/package/withdraw"
    })
  },
  //选项卡点击
  change:function(e){
      this.setData({index:e.target.id})
  },
  //触摸滑动
  touch_change:function(e){
     console.log(e)
    // return
    this.setData({index:e.detail.current})
  },
  /**
 * 金额list
 */
getScoreList:function(){
  var self=this
  core.post("Credit1Log",{page:self.data.list_page,type:'credit1'},function(res){
    if(res.code==1){     
        var current=self.data.list
        for(var i=0;i<res.data.length;i++){
          current.push(res.data[i])
        }
        self.setData({list:current,list_fresh:false,list_page:self.data.list_page+1})
    }
  })
},
  /**
 * 金币list
 */
getFeeList:function(){
  var self=this
  core.post("Credit1Log",{page:self.data.fee_page,type:'credit2'},function(res){
    if(res.code==1){     
        var current=self.data.fee
        for(var i=0;i<res.data.length;i++){
          current.push(res.data[i])
        }
        self.setData({fee:current,fee_fresh:false,fee_page:self.data.fee_page+1})
    }
  })
},
})